package com.dhu.demo.service;


import com.dhu.demo.entity.Classtable;
import com.dhu.demo.entity.Level;
import com.dhu.demo.entity.Student;
import com.dhu.demo.mapper.Classtablemapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassTableService {

    @Autowired
    private Classtablemapper classtablemapper;

    public List<Classtable> findAll(){return classtablemapper.findAll();}
    public List<String> findAllClassTableTeacher(){return classtablemapper.findAllClassTableTeacher();}
    public int insert(Classtable record){
        return classtablemapper.insert(record);
    }
    public int deleteByPrimaryKey(String classname){
        return classtablemapper.deleteByPrimaryKey(classname);
    }
    public int updateByPrimaryKey(Classtable record){
        return classtablemapper.updateByPrimaryKey(record);
    }

    public String calculatingLevel(String classname,int score){
        List<Level> level=classtablemapper.selectLevelByClassname(classname);
        Level levels = level.get(0);
        int a=levels.getAlevel();
        int b=levels.getBlevel();
        int c=levels.getClevel();
        int d=levels.getDlevel();
        if(score>=a) {
            return "A";
        }
        else if (score>=b){
            return "B";
        }
        else if(score>=c){
            return "C";
        }
        else if (score>=d){
            return "D";
        }
        else {
            return "E";
        }
    }

}
